<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" >

  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/turbolinks/5.2.0/turbolinks.js" integrity="sha256-iM4Yzi/zLj/IshPWMC1IluRxTtRjMqjPGd97TZ9yYpU=" crossorigin="anonymous"></script>
  <link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Cousine|Inconsolata" rel="stylesheet">
  <link rel="shortcut icon" type="image/png" href="/favicon.png">

  <link rel="stylesheet" href="/css/style.css">
  <link rel="stylesheet" href="/css/css/fontawesome-all.min.css">
  <link rel="stylesheet" href="/css/css/work-sans-v7.css">
  <script src="/js/main.js"></script>

  <!-- Begin Jekyll SEO tag v2.6.1 -->
<title>RB: Get Follower And Following List | Hive Developer</title>
<meta name="generator" content="Jekyll v4.0.0" />
<meta property="og:title" content="RB: Get Follower And Following List" />
<meta property="og:locale" content="en_US" />
<meta name="description" content="How to create a list of followers and accounts that you are following." />
<meta property="og:description" content="How to create a list of followers and accounts that you are following." />
<link rel="canonical" href="get_follower_and_following_list.html" />
<meta property="og:url" content="get_follower_and_following_list.html" />
<meta property="og:site_name" content="Hive Developer" />
<meta property="og:type" content="article" />
<meta property="article:published_time" content="2020-08-26T11:52:22-07:00" />
<script type="application/ld+json">
{"description":"How to create a list of followers and accounts that you are following.","mainEntityOfPage":{"@type":"WebPage","@id":"get_follower_and_following_list.html"},"@type":"BlogPosting","url":"get_follower_and_following_list.html","headline":"RB: Get Follower And Following List","dateModified":"2020-08-26T11:52:22-07:00","datePublished":"2020-08-26T11:52:22-07:00","@context":"https://schema.org"}</script>
<!-- End Jekyll SEO tag -->


  
</head>
<body>
<header>
  <h1>
    <button type="button" class="open-nav" id="open-nav"></button>
    <a href="/"  class="logo-link"><img src="/images/logotype_black.svg" height="40" alt="Hive Developer logo"></a>
  </h1>

  
  <form action="/search/" method="get">
    <input type="text" name="q" id="search-input" placeholder="Search">
    <input type="submit" value="Search" style="display: none;">
  </form>
  

  <div id="sidebar" class="sidebar">
	
	
	
		
    <section class="pnl-main-nav-section main-nav-section" url="/">
		<h6 class="ctrl-nav-section title">Introduction</h6>
		<ul class="cont-nav-section content">
			
				
					
					
						
						<li><a href="/#introduction-welcome">Welcome to Hive</a></li>
						
					
				
			
		</ul>
	</section>
	
		
    <section class="pnl-main-nav-section main-nav-section" url="/quickstart/">
		<h6 class="ctrl-nav-section title">Quickstart</h6>
		<ul class="cont-nav-section content">
			
				
					
					
						
						<li><a href="/quickstart/#quickstart-choose-library">Choose Library</a></li>
						
					
						
						<li><a href="/quickstart/#quickstart-hive-full-nodes">Hive Nodes</a></li>
						
					
						
						<li><a href="/quickstart/#quickstart-testnet">Hive Testnet</a></li>
						
					
				
			
		</ul>
	</section>
	
		
    <section class="pnl-main-nav-section main-nav-section" url="/tutorials/">
		<h6 class="ctrl-nav-section title">Tutorials</h6>
		<ul class="cont-nav-section content">
			
				
					
						<li><a href="/tutorials/#tutorials-javascript">Javascript</a></li>
					
				
					
						<li><a href="/tutorials/#tutorials-python">Python</a></li>
					
				
					
						<li><a href="/tutorials/#tutorials-ruby">Ruby</a></li>
					
				
					
						<li><a href="/tutorials/#tutorials-recipes">Recipes</a></li>
					
				
			
		</ul>
	</section>
	
		
    <section class="pnl-main-nav-section main-nav-section" url="/services/">
		<h6 class="ctrl-nav-section title">Services</h6>
		<ul class="cont-nav-section content">
			
				
					
					
						
						<li><a href="/services/#services-hive-blog">hive.blog</a></li>
						
					
						
						<li><a href="/services/#services-hivesigner">HiveSigner</a></li>
						
					
						
						<li><a href="/services/#services-jussi">Jussi</a></li>
						
					
						
						<li><a href="/services/#services-imagehoster">ImageHoster</a></li>
						
					
						
						<li><a href="/services/#services-dhf">DHF</a></li>
						
					
				
			
		</ul>
	</section>
	
		
    <section class="pnl-main-nav-section main-nav-section" url="/apidefinitions/">
		<h6 class="ctrl-nav-section title">Appbase API</h6>
		<ul class="cont-nav-section content">
			
				
					
					
						
						<li><a href="/apidefinitions/#apidefinitions-condenser-api">Condenser Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-bridge">Bridge</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-account-by-key-api">Account By Key Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-account-history-api">Account History Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-block-api">Block Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-database-api">Database Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-debug-node-api">Debug Node Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-follow-api">Follow Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-jsonrpc">Jsonrpc</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-market-history-api">Market History Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-network-broadcast-api">Network Broadcast Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-rc-api">Rc Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-reputation-api">Reputation Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-rewards-api">Rewards Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-tags-api">Tags Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-transaction-status-api">Transaction Status Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-witness-api">Witness Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-broadcast-ops">Broadcast Ops</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-broadcast-ops-communities">Broadcast Ops Communities</a></li>
						
					
				
			
		</ul>
	</section>
	
		
    <section class="pnl-main-nav-section main-nav-section" url="/resources/">
		<h6 class="ctrl-nav-section title">Resources</h6>
		<ul class="cont-nav-section content">
			
				
					
					
						
						<li><a href="/resources/#resources-overview">Overview</a></li>
						
					
						
						<li><a href="/resources/#resources-client-libs">Client Libraries</a></li>
						
					
						
						<li><a href="/resources/#resources-bluepaper">Bluepaper</a></li>
						
					
						
						<li><a href="/resources/#resources-whitepaper">Whitepaper</a></li>
						
					
						
						<li><a href="/resources/#resources-tools">Tools</a></li>
						
					
						
						<li><a href="/resources/#resources-hivesigner-libs">Hivesigner Libs</a></li>
						
					
						
						<li><a href="/resources/#resources-hive-keychain">Hive Keychain</a></li>
						
					
						
						<li><a href="/resources/#resources-developeradvocate">Community & Help</a></li>
						
					
				
			
		</ul>
	</section>
	
		
    <section class="pnl-main-nav-section main-nav-section" url="/glossary/">
		<h6 class="ctrl-nav-section title">Glossary</h6>
		<ul class="cont-nav-section content">
			
				
					
					
						
						<li><a href="/glossary/#glossary-chain-basics">Chain Basics</a></li>
						
					
						
					
						
						<li><a href="/glossary/#glossary-governance">Governance</a></li>
						
					
						
						<li><a href="/glossary/#glossary-transactions">Transactions</a></li>
						
					
						
						<li><a href="/glossary/#glossary-api">API</a></li>
						
					
						
						<li><a href="/glossary/#glossary-market">Market</a></li>
						
					
				
			
		</ul>
	</section>
	
</div>



  <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
</header>
<div class="main" id="top">
  <div class="hero">
    <h1 class="hero__h1">Hive Developer Portal </h1>
    <img class="hero__img" src="/images/honey-comb-92.png" style="position: relative; top: 10px;" />
  </div>
  <section id="tutorials-ruby-get-follower-and-following-list" class="row tutorials-ruby-get-follower-and-following-list">
	<h3>
		<a id="tutorials-ruby-get-follower-and-following-list">
			RB: Get Follower And Following List
			
		</a>
	</h3>
	
		<span class="description"><p><em>How to create a list of followers and accounts that you are following.</em></p>
</span>
	

	<p><span class="fa-pull-left top-of-tutorial-repo-link"><span class="first-word">Full</span>, runnable src of <a href="https://gitlab.syncad.com/hive/devportal/-/tree/master/tutorials/ruby/tutorials/19_get_follower_and_following_list">Get Follower And Following List</a> can be downloaded as part of: <a href="https://gitlab.syncad.com/hive/devportal/-/tree/master/tutorials/ruby">tutorials/ruby</a>.</span>
<br /></p>

<p>This tutorial will take you through the process of requesting either the <code class="highlighter-rouge">follower</code> or <code class="highlighter-rouge">following</code> list for an account on the blockchain.</p>

<h2 id="intro">Intro</h2>

<p>In <code class="highlighter-rouge">radiator</code>, we can request follow results using <code class="highlighter-rouge">condenser_api.get_following</code> or <code class="highlighter-rouge">condenser_api.get_follows</code> methods.  These methods take the following arguments:</p>

<ul>
  <li><code class="highlighter-rouge">account</code> - The account for which the follower/following process will be executed.</li>
  <li><code class="highlighter-rouge">start</code> - Where in the list to begin getting results.</li>
  <li><code class="highlighter-rouge">type</code> - We are going to pass <code class="highlighter-rouge">blog</code> for all requests to only request follow results (as opposed to mute results, which takes the value: <code class="highlighter-rouge">ignore</code>).</li>
  <li><code class="highlighter-rouge">limit</code> - The number of lines to be returned by the query (<code class="highlighter-rouge">limit</code>, maximum 1000 per call)</li>
</ul>

<h2 id="steps">Steps</h2>

<ol>
  <li><a href="#connection"><strong>Configure connection</strong></a> Configuration of <code class="highlighter-rouge">radiator</code> to communicate with the Steem blockchain</li>
  <li><a href="#input"><strong>Input variables</strong></a> Collecting the required inputs via command line arguments</li>
  <li><a href="#query"><strong>Get followers/following</strong></a> Get the followers or accounts being followed</li>
  <li><a href="#display"><strong>Display</strong></a> Return the array of results to the console</li>
</ol>

<h4 id="1-configure-connection">1. Configure connection<a name="connection"></a></h4>

<p>In the first few lines we initialize the configured library and packages (libraries are described in <code class="highlighter-rouge">Gemfile</code>):</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">require</span> <span class="s1">'rubygems'</span>
<span class="nb">require</span> <span class="s1">'bundler/setup'</span>

<span class="no">Bundler</span><span class="p">.</span><span class="nf">require</span>

<span class="n">api</span> <span class="o">=</span> <span class="no">Radiator</span><span class="o">::</span><span class="no">Api</span><span class="p">.</span><span class="nf">new</span>
</code></pre></div></div>

<p>Above, we have <code class="highlighter-rouge">radiator</code> pointing to the production network.  To specify a different full node, e.g.:</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">api</span> <span class="o">=</span> <span class="no">Radiator</span><span class="o">::</span><span class="no">Api</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="ss">url: </span><span class="s1">'https://testnet.steemitdev.com'</span><span class="p">)</span>
</code></pre></div></div>

<h4 id="2-input-variables">2. Input variables<a name="input"></a></h4>

<p>Capture the arguments from the command line.</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">account</span> <span class="o">=</span> <span class="no">ARGV</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">type</span> <span class="o">=</span> <span class="no">ARGV</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">||</span> <span class="s1">'following'</span>
<span class="n">limit</span> <span class="o">=</span> <span class="p">(</span><span class="no">ARGV</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">||</span> <span class="s1">'-1'</span><span class="p">).</span><span class="nf">to_i</span>
</code></pre></div></div>

<h4 id="3-get-followersfollowing">3. Get followers/following<a name="query"></a></h4>

<p>Depending on the arguments passed, we call the corresponding method and the element name of what we are requesting:</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">method</span> <span class="o">=</span> <span class="s2">"get_</span><span class="si">#{</span><span class="n">type</span><span class="si">}</span><span class="s2">"</span>
<span class="n">elem</span> <span class="o">=</span> <span class="n">type</span><span class="p">.</span><span class="nf">sub</span><span class="p">(</span><span class="sr">/s/</span><span class="p">,</span> <span class="s1">''</span><span class="p">).</span><span class="nf">to_sym</span>
</code></pre></div></div>

<p>The name of the <code class="highlighter-rouge">elem</code> value stored corresponds with the result elements we’re interested in.  For method calls on <code class="highlighter-rouge">get_following</code>, we want the <code class="highlighter-rouge">following</code> elements.  For method calls on <code class="highlighter-rouge">get_followers</code>, we want <code class="highlighter-rouge">follower</code> elements.</p>

<h4 id="4-display">4. Display<a name="display"></a></h4>

<p>Iterate multiple calls to capture all of the results.</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">until</span> <span class="n">count</span> <span class="o">&gt;=</span> <span class="n">result</span><span class="p">.</span><span class="nf">size</span>
  <span class="n">count</span> <span class="o">=</span> <span class="n">result</span><span class="p">.</span><span class="nf">size</span>
  <span class="n">response</span> <span class="o">=</span> <span class="n">api</span><span class="p">.</span><span class="nf">send</span><span class="p">(</span><span class="nb">method</span><span class="p">,</span> <span class="n">account</span><span class="p">,</span> <span class="n">result</span><span class="p">.</span><span class="nf">last</span><span class="p">,</span> <span class="n">what</span><span class="p">,</span> <span class="p">[</span><span class="n">limit</span><span class="p">,</span> <span class="mi">100</span><span class="p">].</span><span class="nf">max</span><span class="p">)</span>
  <span class="nb">abort</span> <span class="n">response</span><span class="p">.</span><span class="nf">error</span><span class="p">.</span><span class="nf">message</span> <span class="k">if</span> <span class="o">!!</span><span class="n">response</span><span class="p">.</span><span class="nf">error</span>
  <span class="n">result</span> <span class="o">+=</span> <span class="n">response</span><span class="p">.</span><span class="nf">result</span><span class="p">.</span><span class="nf">map</span><span class="p">(</span><span class="o">&amp;</span><span class="n">elem</span><span class="p">)</span>
  <span class="n">result</span> <span class="o">=</span> <span class="n">result</span><span class="p">.</span><span class="nf">uniq</span>
<span class="k">end</span>
</code></pre></div></div>

<h3 id="to-run">To Run</h3>

<p>First, set up your workstation using the steps provided in <a href="https://developers.steem.io/tutorials-ruby/getting_started">Getting Started</a>.  Then you can create and execute the script (or clone from this repository):</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git clone git@github.com:steemit/devportal-tutorials-rb.git
<span class="nb">cd </span>devportal-tutorials-rb/tutorials/19_get_follower_and_following_list
bundle <span class="nb">install
</span>ruby get_follow.rb
</code></pre></div></div>

<hr />

</section>

</div>
<div class="footer">
  <a href="#">Back to top</a>
</div>
<script>
    document.getElementById("open-nav").addEventListener("click", function () {
        document.body.classList.toggle("nav-open");
    });
</script>
</body>
</html>


<script src="/js/adjust.js"></script>

